//
//  OtherShopCell.m
//  成都咖啡
//
//  Created by figaro on 16/3/29.
//  Copyright © 2016年 wenhao. All rights reserved.
//

#import "OtherShopCell.h"
#import "OtherShopCollecitonCell.h"
#import <BmobSDK/Bmob.h>
#import "ShoppingName.h"
#import <UIImageView+WebCache.h>

@interface OtherShopCell(){

    NSArray *otherShop;
}
@end

@implementation OtherShopCell

- (void)awakeFromNib {
    
    self.collectionView.delegate = self;
    self.collectionView.dataSource = self;
    
    [self.collectionView registerNib:[UINib nibWithNibName:@"OtherShopCollecitonCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"OtherShopCollecitonCell"];
    self.collectionView.backgroundColor = [UIColor whiteColor];
    
    //得到Bmob数据
    BmobQuery *query = [BmobQuery queryWithClassName:@"ShopInfo"];
    NSString *otherShopObjectIDString = [ShoppingName shareShoppingName].selectedObjectID;
    //在分类约束下的值：在ShopInfo表里，shopTag里面不同tag值的数组bquery
    [query whereKey:@"objectId" notEqualTo:otherShopObjectIDString];
    
    //查找GameScore表的数据
    [query findObjectsInBackgroundWithBlock:^(NSArray *array, NSError *error) {
        if (error) {
            UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"友情提示" message:@"无法获取数据，请检查网络(☆_☆)" delegate:self cancelButtonTitle:@"关闭" otherButtonTitles:nil, nil];
            [alertView show];
        } else {
            otherShop = [NSArray arrayWithObjects:array[0],array[1],array[2], nil];
          
            [self.collectionView reloadData];
        }
        
        
        
    }];


    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
#warning Incomplete implementation, return the number of sections
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
#warning Incomplete implementation, return the number of items
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    OtherShopCollecitonCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"OtherShopCollecitonCell" forIndexPath:indexPath];
    NSURL *imageUrl = [NSURL URLWithString:[[otherShop objectAtIndex:indexPath.row] objectForKey:@"shop_picture"]];
    [cell.otherShopImage  sd_setImageWithURL:imageUrl];
    cell.backgroundColor = [UIColor whiteColor];
    
    return cell;
}

@end
